package com.goldgov.mobile;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.appdownload.service.AppDownload;
import com.goldgov.appdownload.service.AppDownloadService;
import com.goldgov.distancelearning.service.Distancelearning;
import com.goldgov.distancelearning.service.DistancelearningService;
import com.goldgov.kcloud.core.json.JsonSuccessObject;
import com.goldgov.ms.adapter.call.RemoteCallService;
import com.goldgov.notice.service.NoticeService;
import com.goldgov.notice.service.NoticeUserService;
import com.goldgov.notifyrecord.service.NotifyRecordService;
import com.goldgov.utils.PrintUtil;
import com.goldgov.utils.PropertyUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/** 
 * @ClassName: DistancelearningForMobileController 
 * @Description: 远程教育移动接口
 * @author hanxiangyu
 * @date 2018年6月27日 上午11:04:36 
 */

@RestController
@RequestMapping("/mobile/open")
@Api("远程教育移动接口")
public class ForMobileOpenController {
	
	@Autowired
	private DistancelearningService distancelearningService;
	@Autowired
	private NotifyRecordService notifyRecordService;
	
	@Autowired
	private NoticeService noticeService;
	
	@Autowired
	private NoticeUserService noticeUserService;
	
	@Autowired
	private RemoteCallService remoteCallService;

	@Autowired
	private AppDownloadService appDownloadService;
	
	@RequestMapping("/distancelearning/updateLiveStatus")
	@ApiOperation(value = "更新直播信息", notes ="对远程教育直播信息操作")
	public void updateLiveStatus(Distancelearning obj,HttpServletRequest request,HttpServletResponse response,Model model) {
		try {
//			Distancelearning dis = distancelearningService.getDisByLiveId(obj.getLiveId());
//			if (dis != null && dis.getDistancelearningID() != null) {
//				obj.setDistancelearningID(dis.getDistancelearningID());
//			}
			distancelearningService.updateLiveStatus(obj);
			PrintUtil.print(response, true);
			model.addAttribute("msg", "成功");
		} catch (Exception e) {
			e.printStackTrace();
			PrintUtil.print(response, false);
			model.addAttribute("msg", "失败");
		}
	}
	@RequestMapping("/distancelearning/uploadVideo")
	@ApiOperation(value = "上传会议录像视频", notes ="上传会议录像视频")
	public void uploadVideo(Distancelearning obj,HttpServletRequest request,HttpServletResponse response,Model model) {
		try {
			distancelearningService.updateLiveStatus(obj);
			PrintUtil.print(response, true);
			model.addAttribute("msg", "成功");
		} catch (Exception e) {
			e.printStackTrace();
			PrintUtil.print(response, false);
			model.addAttribute("msg", "失败");
		}
	}
	
	@PostMapping("/distancelearning/updateDisImg")
	@ApiOperation(value = "更新封面图", notes ="更新封面图")
	public void updateDisImg(Distancelearning obj,HttpServletRequest request,HttpServletResponse response,Model model) {
		try {
			distancelearningService.updateDisById(obj);
			PrintUtil.print(response, true);
			model.addAttribute("msg", "成功");
		} catch (Exception e) {
			e.printStackTrace();
			PrintUtil.print(response, false);
			model.addAttribute("msg", "失败");
		}
	}
	
	
	@GetMapping("/getDate")
	@ApiOperation(value = "二维码生成获取当前时间", notes ="二维码生成获取当前时间")
	public JsonSuccessObject<String> getDate(HttpServletRequest request,HttpServletResponse response,Model model){
		String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		JsonSuccessObject<String> returnResult = new JsonSuccessObject<>(format);
		return returnResult;
	}
	
	
	
	
	/**
	 * 新增或更新app数量
	 * @date 2018年12月19日 下午2:15:05 
	 * @author hanxiangyu
	 * @param appDownload
	 * @param request
	 * @param response
	 */
	@GetMapping("/appdownload/saveOrUpdateAppDownload")
	@ApiOperation(value = "新增或更新app信息", notes = "新增或更新app信息" )
	public void saveOrUpdateAppDownload(AppDownload appDownload,HttpServletRequest request,
			HttpServletResponse response,Model model) {
		if (PropertyUtil.objectNotEmpty(appDownload.getDeviceId())) {
			appDownloadService.saveOrUpdateAppDownload(appDownload);
			PrintUtil.printMsg(response, true, "成功");
		}else {
			PrintUtil.printMsg(response, false, "移动设备标识为空！");
		}
	}
	
	
	
}
